package day0301;

public class Demo {

    public static void main(String[] args) {
        String str = "abcdefghi";

//        System.out.println(str.contains("abd"));
//
//        System.out.println(str.indexOf("bcd"));
//
//
//
//        System.out.println(str.indexOf("b", 2));

        subStr(str);

    }
    
    public static void subStr(String str) {
        int max = 1;
        String maxSub = "";
        for (int start = 0; start < str.length(); start++) {

            out:for (int end = start + 1; end < str.length() + 1; end++) {
                String substring = str.substring(start, end);
                // 子串中不能出现重复的
                for (int i = 0; i < substring.length(); i++) {
                    String replaceStr = substring.replace(substring.substring(i, i + 1), "");
                    if (replaceStr.length() != substring.length() - 1) {
                        continue out;
                    }
                }

                // 一定是不重复的
                if (substring.length() > max) {
                    max = substring.length();
                    maxSub = substring;
                }
            }
        }

        System.out.println(maxSub);
        System.out.println(max);
    }
}
